using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.UI.ImageFilter;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class DriftBottleSetHeadCtrl : UserControl
	{
		private const string TAG = "DriftBottleSetHeadCtrl";
		public UITaskDlgEx mDlgDoWithFather;
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchContactListChange;
		private Stream mStreamPic;
		internal Grid LayoutRoot;
		internal Button btnSetHead;
		internal Image imgHead;
		private bool _contentLoaded;
		public DriftBottleSetHeadCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
			if (!this.mBIsFirstLoaded)
			{
				return;
			}
			this.mBIsFirstLoaded = true;
			BitmapImage bottletHeadimg = AccountMgr.getBottletHeadimg();
			this.imgHead.set_Source(bottletHeadimg);
			Log.smethod_5("DriftBottleSetHeadCtrl", "Control_Loaded");
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("DriftBottleSetHeadCtrl", "Control_Unloaded");
		}
		private void registerEvent()
		{
			if (this.mWatchContactListChange == null)
			{
				this.mWatchContactListChange = new EventWatcher(this, this, new EventHandlerDelegate(this.OnContactChange));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchContactListChange);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchContactListChange != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchContactListChange);
				this.mWatchContactListChange = null;
			}
		}
		private void OnContactChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
		}
		private void btnSetHead_Click(object sender, RoutedEventArgs e)
		{
			if (BasePage.CanDoBackSysTask())
			{
				BasePage.DoBackSysTask();
				ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
				{
					new ImageFilterConfig(new ImageFilterCallBack(this.onImageFilterCallBack), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 480, 480, null)
					{
						isSaveToAlbum = true,
						isNeedFilter = true
					}
				}, false);
				return;
			}
		}
		private void onImageFilterCallBack(Stream resultData)
		{
			this.mStreamPic = resultData;
			if (this.mStreamPic != null)
			{
				if (this.mDlgDoWithFather != null)
				{
					this.mDlgDoWithFather(BtleSetHeadOpKind.OpKind_SetStart);
				}
				HDheadImgMgr.uploadDriftBottleImg(this.mStreamPic, new onUploadHDheadImgCallback(this.onUploadHDheadImgCallback));
			}
		}
		private void onUploadHDheadImgCallback(bool bSuccess)
		{
			if (this.mDlgDoWithFather != null)
			{
				this.mDlgDoWithFather(BtleSetHeadOpKind.OpKind_SetEnd);
			}
			if (!bSuccess)
			{
				MMMessageBox.Show(strings.Set_Personal_SendImage_Err, true, "确定");
				return;
			}
			AccountMgr.saveBottleHeadImg(this.mStreamPic);
			MessageBoxManager.ShowToast(strings.Set_Personal_SendImage_OK, 2500, null, false);
			if (this.mStreamPic == null)
			{
				return;
			}
			BitmapImage bitmapImage = new BitmapImage();
			bitmapImage.SetSource(this.mStreamPic);
			this.imgHead.set_Source(bitmapImage);
		}
		public void Init(UITaskDlgEx uitaskDlgEx_0)
		{
			this.mDlgDoWithFather = uitaskDlgEx_0;
			this.registerEvent();
		}
		public void UnInit()
		{
			this.mDlgDoWithFather = null;
			this.unRegisterEvent();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/DriftBottle/UI/DriftBottleSetHeadCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.btnSetHead = (Button)base.FindName("btnSetHead");
			this.imgHead = (Image)base.FindName("imgHead");
		}
	}
}
